package cn.kduck.code.entity.query;

import cn.kduck.core.dao.definition.BeanDefDepository;
import cn.kduck.core.dao.definition.BeanEntityDef;
import cn.kduck.core.dao.query.QueryCreator;
import cn.kduck.core.dao.query.QuerySupport;
import cn.kduck.core.dao.sqlbuilder.ConditionBuilder.ConditionType;
import cn.kduck.core.dao.sqlbuilder.SelectBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

import static cn.kduck.code.entity.service.EntityService.CODE_ENTITY;

@Component
public class EntityQuery implements QueryCreator {

    @Override
    public QuerySupport createQuery(Map<String, Object> paramMap, BeanDefDepository depository) {
        BeanEntityDef entityDef = depository.getEntityDef(CODE_ENTITY);
        SelectBuilder selectBuilder = new SelectBuilder(entityDef, paramMap);
        selectBuilder.where()
                .and("ENTITY_CODE", ConditionType.EQUALS,"entityCode")
                .orderBy().asc("ENTITY_CODE");
        return selectBuilder.build();
    }
}
